@isTest
private class UpdateRoutingPlan_TestClass {

    static testMethod void myUnitTest() {
        Profile pTsr = [select id from profile where  name = 'Sales Rep - Trade' limit 1];
        
        User uTsr = new User(alias='standtss',email='sduser@testorgss.com',emailencodingkey='UTF-8', lastname='Testeing',
        languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles',profileid=pTsr.Id,
        Title__c='Sales Rep',FunctionDepartment__c='Trade Sales', 
        username='stsers@testorg.com');
        insert uTsr;
        
        System.runAs(uTsr)
        {
             Account acc=new Account();
             acc.Name='test';
             acc.Channel__c='特大型综合超市';
             acc.Outlet_Type__c='全国重点客户';
             acc.Contact__c='aaa';
             acc.No_of_checkout__c=22;
             acc.ContactPhoneNumber__c='1234567456';
             acc.OwnerId=uTsr.Id;
             insert acc;
         
            Routing_Plan_And_Visit__c r=new Routing_Plan_And_Visit__c(Visit_Date__c=System.today().addMonths(1),OwnerId=uTsr.Id);
            insert r;
            RoutingPlan__c rp=new RoutingPlan__c();
            rp.RoutingPlanAndVisit__c=r.Id;
            rp.OutletName__c=acc.Id;
           // DateTime d=System.today().addMonths(1);
            rp.StartDateTime__c=DateTime.newInstance(r.Visit_Date__c.year(),r.Visit_Date__c.Month(),r.Visit_Date__c.Day(),9,9,9);
            rp.EndDateTime__c=DateTime.newInstance(r.Visit_Date__c.year(),r.Visit_Date__c.Month(),r.Visit_Date__c.Day(),12,12,9);
            insert rp;
            
            List<Routing_Plan_And_Visit__c> rList=[select Id,Visit_Date__c,OwnerId from Routing_Plan_And_Visit__c where Visit_Date__c=:System.today().addMonths(1)];
            List<Routing_Plan_And_Visit__c> lr=new List<Routing_Plan_And_Visit__c>();
            for(Integer i=0;i<rList.size();i++)
            {
                rList[i].Visit_Date__c=System.today().addMonths(2);
                lr.add(rList[i]);
            }
            update lr;
        }
    }
}